package classification.imp;

import classification.PaymentClassification;
import domain.SalesReceipt;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class CommissionedClassification implements PaymentClassification {
    private double commissionRate;
    private double monthlySalary;
    private Map<Date, SalesReceipt> dateSalesReceiptMap = new HashMap<>();

    public CommissionedClassification(double monthlySalary, double commissionRate) {
        this.monthlySalary = monthlySalary;
        this.commissionRate = commissionRate;
    }

    public double getMonthlySalary() {
        return monthlySalary;
    }

    public double getCommissionRate() {
        return commissionRate;
    }

    public void setCommissionRate(double commissionRate) {
        this.commissionRate = commissionRate;
    }

    public void setMonthlySalary(double monthlySalary) {
        this.monthlySalary = monthlySalary;
    }

    public void addSalesReceipt(SalesReceipt salesReceipt) {
        dateSalesReceiptMap.put(salesReceipt.getDate(), salesReceipt);
    }

    public SalesReceipt getSalesReceipt(Date date) {
        SalesReceipt salesReceipt = dateSalesReceiptMap.get(date);
        return salesReceipt;
    }

    @Override
    public double calcGrossPay() {
        double sum = 0;
        for(Date date : dateSalesReceiptMap.keySet()) {
            sum += dateSalesReceiptMap.get(date).getAmount();
        }
        dateSalesReceiptMap.clear();
        return monthlySalary + sum * commissionRate;
    }
}
